<%--
  Created by IntelliJ IDEA.
  User: MyDream
  Date: 2020/8/24
  Time: 14:40
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="_linkPages/basePath.jsp"%>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="${basePath}static/css/style.css" />
    <link rel="stylesheet" type="text/css" href="${basePath}static/css/shopping-mall-index.css" />
    <link rel="stylesheet" type="text/css" href="${basePath}static/css/zhonglingxm2.css" />
    <script type="text/javascript" src="${basePath}static/js/jquery.js"></script>
    <script type="text/javascript" src="${basePath}static/js/zhonglin.js"></script>
    <script src="${basePath}static/js/jquery-1.4.2.min.js"></script>
</head>

<body>

<div class="sign-logo w1200">
    <h1 class="zl-h11"><a href="index?method=toIndex" title="宅客微购"><img src="${basePath}static/images/zl2-01.gif" /></a></h1>
</div>

<div class="sign-con w1200">
    <img src="${basePath}static/images/logn-tu.gif" class="sign-contu f-l" />
    <form action="${basePath}loginDp?method=login" method="post" onsubmit=" return checkLogin(this)">
        <div class="sign-ipt f-l">
            <span name="msg" id="msg" style="text-align: center;size: 20px; color: red; height: 40px; width: 200px;" >
                ${msg}
            <c:remove var="msg" scope="session"/>
            </span>
            <input type="hidden" name="method" value="login" />
            <p>用户名</p>
            <input type="text" id="username" name="username" placeholder="请输入用户名" onblur="checkUsername()"/>
            <p>密码</p>
            <input type="password" id="password" name="password" placeholder="请输入密码" onblur="checkPassword()" /><br />
            <button type="submit" class="slig-btn">登录</button>
            <p>没有账号？请<a href="${basePath}loginDp?method=toRegPage">注册</a><a href="${basePath}loginDp?method=toFindPage" class="wj">忘记密码？</a></p>
        </div>
    </form>
    <div style="clear:both;"></div>
</div>

</body>

<script>
    var pwd = '';
    var name = '';
    var regUsername = /^\w{5,15}$/;
    var regPassword = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/

    function checkLogin(frm) {
        let msg = frm.msg;
        let username = frm.username.value;
        let password = frm.password.value;

        if (!regUsername.test(username) || name == 1 || !regPassword.test(password)) {
            msg.innerHTML = '用户名或密码错误';
            return false;
        }
        return true;

    }

    function checkUsername() {
        let msg = document.getElementById("msg");
        let username = document.getElementById("username").value;
        $.post("${basePath}loginDP?method=checkUsername&username=" + username, function (data) {
            // 如果传过来的数据不为空
            if (data == -1) {
                name = data;
                console.log(data);
            } else {
                msg.innerHTML = '用户名错误';
            }
        },'json');

    }

    function checkPassword() {
        let msg = document.getElementById("msg");
        let password = document.getElementById("password").value;
        if (!regPassword.test(password)) {
            msg.innerHTML = '密码不正确';
            msg.style.display = 'inline';
        } else {
            msg.style.display = 'none';
        }

    }
</script>
</html>
